{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[0 1 2]\n",
      "[ 0.          1.          1.41421356]\n"
     ]
    }
   ],
   "source": [
    "import numpy as np\n",
    "B = np.arange(3)\n",
    "print B\n",
    "#print np.exp(B)\n",
    "print np.sqrt(B)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "None\n",
      "[[ 9.  7.  6.  4.  9.  0.]\n",
      " [ 2.  9.  1.  3.  4.  0.]]\n"
     ]
    }
   ],
   "source": [
    "#Return the floor of the input\n",
    "a = np.floor(10*np.random.random((3,4)))\n",
    "#print a\n",
    "\n",
    "#a.shape\n",
    "## flatten the array\n",
    "#print a.ravel()\n",
    "#a.shape = (6, 2)\n",
    "#print a \n",
    "#print a.T\n",
    "print a.resize((2,6))\n",
    "print a\n",
    "\n",
    "#If a dimension is given as -1 in a reshaping operation, the other dimensions are automatically calculated:\n",
    "#a.reshape(3,-1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[ 5.  6.]\n",
      " [ 1.  5.]]\n",
      "---\n",
      "[[ 8.  6.]\n",
      " [ 9.  0.]]\n",
      "---\n",
      "[[ 5.  6.  8.  6.]\n",
      " [ 1.  5.  9.  0.]]\n"
     ]
    }
   ],
   "source": [
    "a = np.floor(10*np.random.random((2,2)))\n",
    "b = np.floor(10*np.random.random((2,2)))\n",
    "print a\n",
    "print '---'\n",
    "print b\n",
    "print '---'\n",
    "print np.hstack((a,b))\n",
    "#np.hstack((a,b))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[ 5.  2.]\n",
      " [ 1.  3.]\n",
      " [ 9.  6.]\n",
      " [ 2.  2.]\n",
      " [ 7.  2.]\n",
      " [ 8.  2.]\n",
      " [ 1.  7.]\n",
      " [ 2.  8.]\n",
      " [ 4.  4.]\n",
      " [ 8.  5.]\n",
      " [ 4.  3.]\n",
      " [ 2.  3.]]\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "[array([[ 5.,  2.],\n",
       "        [ 1.,  3.],\n",
       "        [ 9.,  6.],\n",
       "        [ 2.,  2.]]), array([[ 7.,  2.],\n",
       "        [ 8.,  2.],\n",
       "        [ 1.,  7.],\n",
       "        [ 2.,  8.]]), array([[ 4.,  4.],\n",
       "        [ 8.,  5.],\n",
       "        [ 4.,  3.],\n",
       "        [ 2.,  3.]])]"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a = np.floor(10*np.random.random((2,12)))\n",
    "#print a\n",
    "#print np.hsplit(a,3)\n",
    "#print np.hsplit(a,(3,4))   # Split a after the third and the fourth column\n",
    "a = np.floor(10*np.random.random((12,2)))\n",
    "print a\n",
    "np.vsplit(a,3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(3, 4)\n",
      "82691200\n",
      "82691200\n"
     ]
    }
   ],
   "source": [
    "#Simple assignments make no copy of array objects or of their data.\n",
    "a = np.arange(12)\n",
    "b = a\n",
    "# a and b are two names for the same ndarray object\n",
    "b is a\n",
    "b.shape = 3,4\n",
    "print a.shape\n",
    "print id(a)\n",
    "print id(b)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[   0,    1,    2,    3],\n",
       "       [1234,    5,    6,    7],\n",
       "       [   8,    9,   10,   11]])"
      ]
     },
     "execution_count": 43,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#The view method creates a new array object that looks at the same data.\n",
    "c = a.view()\n",
    "c is a\n",
    "c.shape = 2,6\n",
    "#print a.shape\n",
    "c[0,4] = 1234\n",
    "a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[9999    1    2    3]\n",
      " [1234    5    6    7]\n",
      " [   8    9   10   11]]\n",
      "[[   0    1    2    3]\n",
      " [1234    5    6    7]\n",
      " [   8    9   10   11]]\n"
     ]
    }
   ],
   "source": [
    "#The copy method makes a complete copy of the array and its data.\n",
    "d = a.copy() \n",
    "d is a\n",
    "d[0,0] = 9999\n",
    "print d \n",
    "print a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.11"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
